$(function () {
    $("#jqGrid").jqGrid({
        url: '../empblacklist/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true ,hidden: true},
			{ label: '姓名', name: 'empName', index: 'emp_name', width: 80 }, 			
			{ label: '员工编号', name: 'empNo', index: 'emp_no', width: 80 }, 			
			{ label: '身份证号', name: 'cardNo', index: 'card_no', width: 80 }, 			
			{ label: '员工状态', name: 'empState', index: 'emp_state', width: 80 ,
                formatter:function(v){
                    if(v=='0'){
                        return "未上岗";
                    }else if(v=='1'){
                        return "已上岗";
                    }else if(v=='2'){
                        return "已离职";
                    }else{
                        return "";
                    }

                }

            },
			{ label: '是否锁定', name: 'ifLock', index: 'if_lock', width: 80 ,
                formatter:function(v){
			     if(v=='0'){
			         return "是";
                 }else if(v=='1'){
                     return "否";
                 }else{
                     return "";
                 }

                }
            },
			{ label: '锁定时间', name: 'lockTime', index: 'lock_time', width: 80 ,formatter:"date", formatoptions: {newformat:'Y-m-d'}},
			{ label: '锁定原因', name: 'lockReason', index: 'lock_reason', width: 80 }, 			
			{ label: '操作人(锁定)', name: 'lockPerson', index: 'lock_person', width: 80 }, 			
			{ label: '解锁时间', name: 'unLockTime', index: 'un_lock_time', width: 80,formatter:"date", formatoptions: {newformat:'Y-m-d'} },
			{ label: '解锁原因', name: 'unLockReason', index: 'un_lock_reason', width: 80 }, 			
			{ label: '解锁人', name: 'unLockPerson', index: 'un_lock_person', width: 80 }, 			
			// { label: '备注', name: 'remark', index: 'remark', width: 80 }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });

});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q: {
            name: null,

        },
		showList: true,
        showtable:false,
		title: null,
		empBlacklist: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
            vm.showtable = false;
			vm.title = "新增";
            vm.empBlacklist = {
                empName:""
            };
            this.getjqGridpersondispatch();
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.showtable = false;

            vm.title = "修改";

            vm.getInfo(id);
            this.getjqGridpersondispatch();

		},
		saveOrUpdate: function (event) {
			vm.empBlacklist.lockTime = $("#lockTime").val();
            vm.empBlacklist.unLockTime = $("#unLockTime").val();
			var url = vm.empBlacklist.id == null ? "../empblacklist/save" : "../empblacklist/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.empBlacklist),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../empblacklist/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../empblacklist/info/"+id, function(r){
                vm.empBlacklist = r.empBlacklist;
            });
		},
		reload: function (event) {
			vm.showList = true;
            vm.showtable = false;

            var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{'emp_name': vm.q.name},
                page:page
            }).trigger("reloadGrid");
		},
        getjqGridpersondispatch: function(){
            $("#jqGridpersondispatch").jqGrid({
                url: '../persondispatch/list',
                datatype: "json",
                colModel: [
                    { label: 'id', name: 'id', index: 'id', key: true, hidden: true },
                    { label: '员工名称', name: 'name', index: 'name' },
                    { label: '身份证', name: 'idno', index: 'idno' },
                    { label: '公司名称', name: 'settlementName', index: 'settlement_name' },
                    { label: '结算点id', name: 'settlementId', index: 'settlement_id' },
                    { label: '人员id', name: 'personId', index: 'person_id' },
                    { label: '入职日期', name: 'entryDate', index: 'entry_date' },
                    { label: '部门', name: 'department', index: 'department' },
                    { label: '岗位', name: 'station', index: 'station' },
                    { label: '派遣类型', name: 'dispatchType', index: 'dispatch_type' },
                    { label: '合同id', name: 'contractId', index: 'contract_id' },
                    { label: '档案状态:未接收、待接收', name: 'fileState', index: 'file_state',width: 300},
                    { label: '档案id', name: 'archivesId', index: 'archives_id' },
                    { label: '工伤:未申报、预申报', name: 'injury', index: 'injury' ,width: 300},
                    { label: '工伤参保日期', name: 'injuryInsuredDate', index: 'injury_insured_date'  },
                    { label: '工伤退保日期', name: 'injurySurrenderDate', index: 'injury_surrender_date' },
                    { label: '养老:未申报、预申报', name: 'pension', index: 'pension' ,width: 300 },
                    { label: '养老参保日期', name: 'pensionInsuredDate', index: 'pension_insured_date' },
                    { label: '养老退保日期', name: 'pensionSurrenderDate', index: 'pension_surrender_date'  },
                    { label: '失业参保情况', name: 'unemployment', index: 'unemployment'},
                    { label: '失业参保日期', name: 'unemploymentInsuredDate', index: 'unemployment_insured_date' },
                    { label: '失业退保日期', name: 'unemploymentSurrenderDate', index: 'unemployment_surrender_date' },
                    { label: '医保', name: 'medicare', index: 'medicare' },
                    { label: '医保申报日期', name: 'medicareInsuredDate', index: 'medicare_insured_date' },
                    { label: '医保退保日期', name: 'medicareSurrenderDate', index: 'medicare_surrender_date' },
                    { label: '生育', name: 'maternity', index: 'maternity'  },
                    { label: '生育参保日期', name: 'maternityInsuredDate', index: 'maternity_insured_date' },
                    { label: '生育退保日期', name: 'maternitySurrenderDate', index: 'maternity_surrender_date'  },
                    { label: '公积金', name: 'accumulationFund', index: 'accumulation_fund'  },
                    { label: '公积金参保日期', name: 'accumulationFundInsuredDate', index: 'accumulation_fund_insured_date' },
                    { label: '公积金退保日期', name: 'accumulationFundSurrenderDate', index: 'accumulation_fund_surrender_date'  },
                    { label: '五险合一:未申报、预申报', name: 'fiveOneInsurance', index: 'five_one_insurance',width: 300 },
                    { label: '操作人', name: 'operator', index: 'operator' },
                    { label: '操作日期', name: 'operationDate', index: 'operation_date'  },
                    { label: '不申报原因', name: 'noDeclareReason', index: 'no_declare_reason'  },
                    { label: '备注', name: 'remark', index: 'remark' },
                    { label: '是否有效', name: 'enable', index: 'enable' }
                ],
                viewrecords: true,
                height: 300,
                width: 900,
                rowNum: 30,
                rowList : [10,30,50],
                rownumbers: true,
                autowidth:false,
                //字段太多自动加载横轴滚动条
                shrinkToFit:false,
                autoScroll: false,
                multiselect:false,//只允许单选
                pager: "#jqGridPagerpersondispatch",
                jsonReader : {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames : {
                    page:"page",
                    rows:"limit",
                    order: "order"
                },
                gridComplete:function(){
                    //doResize();
                    //显示grid底部滚动条
                    //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "scroll" });
                }
            });
        },
        popemployeename:function(){
            utils.openDialogView('单位员工管理',$("#window"),'900px','500px',1);
        },
        unlockInit: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.showtable = true;

            vm.title = "解锁";

            vm.getInfo(id);

        },

        unlock: function (event) {

            var url =  "../empblacklist/unlock" ;
            $.ajax({
                type: "POST",
                url: url,
                contentType: "application/json",
                data: JSON.stringify(vm.empBlacklist),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
	}
});

$("#closepersondispatch").click(function(){
    utils.closeCurrentPage();
});
$("#addpersondispatch").click(function(){
    //判断是否选中了数据
    var id=$("#jqGridpersondispatch").jqGrid('getGridParam','selrow');
    if(id==null){
        alert("请选择一条记录!");
        return ;
    }
    var rowData = $("#jqGridpersondispatch").jqGrid('getRowData',id);
    vm.empBlacklist.empNo=rowData.personId;
    vm.empBlacklist.empName=rowData.name;
    vm.empBlacklist.cardNo=rowData.idno;

    utils.closeCurrentPage();
});
